package com.lxl.commons.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 字符编码过滤器
 * @author 北上寻海
 */
public class CharacterEncodingFilter implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws ServletException, IOException {
        //对请求进行转码
        request.setCharacterEncoding("UTF-8");
        //对响应进行转码
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
    }

}
